package com.elmcode.server.controller.admin;

import com.elmcode.common.utils.PageUtils;
import com.elmcode.common.utils.R;
import com.elmcode.server.dto.FlavorDTO;
import com.elmcode.server.entity.FlavorEntity;
import com.elmcode.server.exception.FlavorException;
import com.elmcode.server.service.FlavorService;
import com.elmcode.server.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;



/**
 * 菜品口味关系表
 *
 * @author laozj
 * @email laozj@elm.com
 * @date 2024-06-13 13:05:04
 */
@Api(tags = "口味接口")
@RestController
@RequestMapping("admin/flavor")
public class FlavorController {

    @Autowired
    private FlavorService flavorService;


    /**
     * 查找所有的口味
     */
    @ApiOperation("查询口味接口")
    @GetMapping
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = flavorService.queryPage(params);

        return Result.ok("查询成功",page.getList(),page.getTotal());
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		FlavorEntity flavor = flavorService.getById(id);

        return R.ok().put("flavor", flavor);
    }

    /**
     * 保存
     */
    @PostMapping
    public Result save(FlavorDTO flavorDTO){
		flavorService.saveFlavor(flavorDTO);

        return Result.ok("保存成功");
    }

    /**
     * 修改
     */
    @PutMapping("/{id}")
    public Result update(@PathVariable("id")Long id, FlavorDTO flavorDTO){
		flavorService.updateFlavor(id,flavorDTO);

        return Result.ok("修改成功");
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Long id){
		flavorService.removeById(id);

        return Result.ok("删除成功");
    }

}
